
public class Complex {
	
	private double imaginary;
	private double real;

	public Complex(int a, int b) {
		this.real = (double) a;
		this.imaginary = (double) b;
	}
	
	public Complex(double a, double b) {
		this.real = a;
		this.imaginary = b;
	}
	
	public Complex() {
		this.imaginary = 0;
		this.real = 0;
	}
	
	public double getReal() {
		return this.real;
	}
	
	public double getIm() {
		return this.imaginary;
	}
	
	public void add(Complex z) {
		this.real += z.getReal();
		this.imaginary += z.getIm();
	}
	
	public void mult(int d) {
		this.real *= d;
		this.imaginary *= real;
	}
	
	public static Complex multNew(Complex a, Complex b) {
		Complex answer = new Complex(a.getReal()*b.getReal() - a.getIm()*b.getIm(), a.getIm()*b.getReal() + a.getReal()*b.getIm());
		return answer;
	}
	
	public static Complex divScalar(Complex z, double d) {
		Complex answer = new Complex(z.getReal()/d, z.getIm()/d);
		return answer;
	}
	
	public static double norm2(Complex z) {
		return z.getReal()*z.getReal() + z.getIm()*z.getIm();
	}
	
	public static Complex Chi(int interval, int var, int n) {
		double arg = (2.0/n)*Math.PI*var*interval;
		double re = Math.cos(arg);
		double im = Math.sin(arg);
		return new Complex(re, im);
	}
	
	public static Complex Chi(double interval, int var, int n) {
		double arg = (2.0/n)*Math.PI*var*interval;
		double re = Math.cos(arg);
		double im = Math.sin(arg);
		return new Complex(re, im);
	}
	
	public boolean isZero() {
		if (this.real == 0 && this.imaginary == 0) {
			return true;
		}
		else {
			return false;
		}
	}
	
	public String toString() {
		if(this.isZero())
			return "0";
		else if(this.real==0)
			return this.imaginary+"i";
		else if(this.imaginary==0)
			return this.real+"";
		else if(this.imaginary<0)
			return this.real+""+this.imaginary+"i";
		return this.real+"+"+this.imaginary+"i";
	}
}